package ui

import applicationModel.Mejora
import applicationModel.MejoraDefensiva
import home.HomeMejoras
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.commons.utils.ApplicationContext
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.widgets.tables.Table
import dominio.Planta
import org.uqbar.arena.widgets.tables.Column
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.bindings.NotNullObservable

 class MejorasWindow extends Dialog<MejoraDefensiva> {

	new(WindowOwner owner, MejoraDefensiva m) {
		super(owner, m)
		//modelObject.start
	}

		override def createMainTemplate(Panel mainPanel) {

		super.createMainTemplate(mainPanel)

		this.createResultsGrid(mainPanel)
		this.createGridActions(mainPanel)
		
	}

	override protected createFormPanel(Panel mainPanel) {
		val editorPanel = new Panel(mainPanel)
		editorPanel.setLayout(new ColumnLayout(2))

	}

	def createResultsGrid(Panel mainPanel) {
		var table = new Table<Planta>(mainPanel, typeof(Planta))
		table.heigth = 200
		table.width = 450
		table.bindItemsToProperty("plantas")
		table.bindValueToProperty("plantaSeleccionada")
		this.describeResultsGrid(table)
	}

	def describeResultsGrid(Table<Planta> table) {
		new Column<Planta>(table) //
		.setTitle("Nombre").setFixedSize(150).bindContentsToProperty("nombre")

		new Column<Planta>(table) //
		.setTitle("Poder Ofensivo").setFixedSize(150).bindContentsToProperty("puntosDanio")

		new Column<Planta>(table) //
		.setTitle("Poder Defensivo").setFixedSize(150).bindContentsToProperty("capacidadDefensiva")
	}

	def void createGridActions(Panel mainPanel) {
		var actionsPanel = new Panel(mainPanel)
		actionsPanel.setLayout(new HorizontalLayout)
	//var edit = new Button(actionsPanel).setCaption("Mejorar").onClick[|this.mejorarPlanta]
		val botonvolver = new Button(actionsPanel).setAsDefault.setCaption("Tablero")
		botonvolver.onClick[|cancel]

		//this.docreateGridActions(mainPanel)
		var elementSelected = new NotNullObservable("plantaSeleccionada")
		//edit.bindEnabled(elementSelected)
	}

	//def void docreateGridActions(Panel mainPanel)

	def void mejorarPlanta() {
		
	}

	def openDialog(Dialog<?> dialog) {
		dialog.onAccept[|]
		this.close
		dialog.open

	}


	def getHomeMejoras() {
		ApplicationContext::instance.getSingleton(typeof(Mejora)) as HomeMejoras
	}

}
